# 第 7 章 用户输入和while 循环
# 7.1 函数input() 的工作原理
# message = input("请输入您的姓名:")
# print(message)
# 7.1.1 编写清晰的程序
# name = input("请输入您的姓名：")
# print("你好，"+name)
# 7.1.2 使用int() 来获取数值输入
# age = input("你多大了?")
# print(age)
# age = int(age)
# print(age >= 18)
# 7.1.3 求模运算符,它将两个数相除并返回余数
# print(4 % 3)
# print(5 % 3)
# print(6 % 3)
# number = input("请输入数字:")
# number=int(number)
# if number % 2 == 0:
#     print("此为偶数"+str(number))
# else:
#     print("此为奇数"+str(number))

# 7.2 while 循环简介
# 7.2.1 使用while 循环
# current_number = 1
# while current_number <= 5:
#     print(current_number)
#     current_number += 1
# 7.2.2 让用户选择何时退出
# prompt = "\n告诉我一件事，我再重复给你听:"
# prompt += "\n输入“quit”结束程序. "
# message = ""
# while message != 'quit':
#     message = input(prompt)
#     if message != 'quit':
#         print(message)
# 7.2.3 使用标志
# prompt = "\n告诉我一件事，我再重复给你听:"
# prompt += "\n输入“quit”结束程序. "
# active = True
# while active:
#     message = input(prompt)
#     if message == 'quit':
#         active = False
#     else:
#         print(message)
# 7.2.4 使用break 退出循环
# prompt = "\n告诉我一件事，我再重复给你听:"
# prompt += "\n输入“quit”结束程序. "
# active = True
# while active:
#     message = input(prompt)
#     if message == 'quit':
#        break
#     else:
#         print(message)
# 7.2.5 在循环中使用continue
# number = 0
# while number <= 10:
#     number += 1
#     if number % 2 == 0:
#         continue
#     else:
#         print(number)
# 7.2.6 避免无限循环
# x = 1
# while x <= 5:
#     print(x)
#     x += 1
# 7.3 使用while 循环来处理列表和字典
# 7.3.1 在列表之间移动元素
# un_user = ['zzp', 'rgp', 'hj']
# config_user=[]
# while un_user:
#     cu_user=un_user.pop()
#     print(cu_user.title())
#     config_user.append(cu_user)
# print("所有通过验证的用户:")
# for user in config_user:
#     print(user.title())
# 7.3.2 删除包含特定值的所有列表元素
pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']
print(pets)
while 'cat' in pets:
    pets.remove('cat')
print(pets)
# 7.3.3 使用用户输入来填充字典
responses = {}
active = True
while active:
    name = input("请输入姓名:")
    response = input("你是男是女:")
    responses[name] = response
    repate = input("还有人回答吗? yes/no")
    if repate == 'no':
        active = False
print("问卷调查结束")
for name, response in responses.items():
    print(name + "  " + response)
